<?php

namespace App\Http\Controllers;

use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Routing\Controller as BaseController;
use App\Utils\ApiResponse;

class Controller extends BaseController
{
    use AuthorizesRequests, DispatchesJobs, ValidatesRequests;

    /**
     * 成功响应
     *
     * @param mixed $data 返回的数据
     * @param string $message 提示信息
     * @param int $code 状态码
     * @return \Illuminate\Http\JsonResponse
     */
    protected function success($data = null, $message = 'success', $code = 200)
    {
        return ApiResponse::success($data, $message, $code);
    }

    /**
     * 失败响应
     *
     * @param string $message 错误信息
     * @param int $code 状态码
     * @param mixed $data 返回的数据
     * @return \Illuminate\Http\JsonResponse
     */
    protected function error($message = 'error', $code = 500, $data = null)
    {
        return ApiResponse::error($message, $code, $data);
    }

    /**
     * 分页数据响应
     *
     * @param mixed $data 数据列表
     * @param \Illuminate\Pagination\LengthAwarePaginator $paginator 分页对象
     * @param string $message 提示信息
     * @return \Illuminate\Http\JsonResponse
     */
    protected function paginated($data, $paginator, $message = 'success')
    {
        return ApiResponse::paginated($data, $paginator, $message);
    }
}